<?php
class ControllerPaymentAuthorizenetAim extends AdminController {

	public function index() {

		if ($this->request->isPost() && $this->validate()) {
			M('setting/setting');
			$this->model_setting_setting->editSetting('authorizenet_aim', $this->request->post);

			$this->session->set_flashdata('success', $this->_['text_success']);
			$this->redirect(UA('extension/payment'));
		}

		$this->document->setTitle($this->_['heading_title']);
		
  		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['text_home'],
			'href'      => UA('common/home'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['text_payment'],
			'href'      => UA('extension/payment'),
      		'separator' => ' :: '
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['heading_title'],
			'href'      => UA('payment/authorizenet_aim'),
      		'separator' => ' :: '
   		);

		M('localisation/order_status');
		$this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();

		M('localisation/geo_zone');
		$this->data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();

		$this->display('payment/authorizenet_aim.tpl');
	}

	protected function validate() {
		if (!$this->hasMP()) {
			$this->setMessage('error_warning', $this->_['error_permission']);
			return false;
		}

		$pass = true;

		if (!$this->request->post['authorizenet_aim_login']) {
			$this->setMessage('error_login', $this->_['error_login']);
			$pass = false;
		}

		if (!$this->request->post['authorizenet_aim_key']) {
			$this->setMessage('error_key', $this->_['error_key']);
			$pass = false;
		}

		return $pass;
	}
}
?>